home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / ENTRY.SWG / 0005_A Simple Input Routine.pas < prev    next >
Pascal/Delphi Source File  |  1993-08-27  |  2KB  |  124 lines

  1. {
  2. SEAN PALMER
  3.  
  4. > name:_______________) problem, how do you make a field where you
  5. > define the max Chars in the field and doNOT let the person Type more
  6. > than that.  stop the users keyboard at the last Char in this Case its
  7. > 78 Chars max and the field looks like this
  8.  
  9. Try this. Send it a default value, the length of the field, and a set of
  10. Char containing all the valid Characters For the field.
  11.  
  12. }
  13. Uses uInput,Crt;
  14.  
  15. Function getName : String;
  16. Const
  17.   nameMax = 20;
  18. Var
  19.   Count    : Integer;
  20.   attrsave : Byte;
  21. begin
  22.   GotoXY(12, 2);
  23.   Write('ENTER NAME:');
  24.   attrsave := TextAttr;
  25.   TextColor(0);
  26.   TextBackground(7);
  27.   GotoXY(26, 2);
  28.   for Count := 1 to nameMax do
  29.     Write(' ');  {draw inverse field}
  30.   GotoXY(26, 2);
  31.   getName  := input('Nobody', nameMax, ['A'..'Z','a'..'z','.',' ']);
  32.   Textattr := attrsave;
  33. end;
  34.  
  35. {----------}
  36.  
  37. {uInput}
  38. {by Sean Palmer}
  39. {released to the public domain}
  40.  {2237 Lincoln St.}
  41.  {Longmont, CO 80501}
  42. {Alms gladly accepted! 8) }
  43.  
  44. Unit uInput;
  45. {$B-,I-,N-,O-,R-,S-,V-,X-}
  46.  
  47. Interface
  48.  
  49. {tCharSet is used to specify Function keys to the input routine}
  50. Type
  51.   tCharSet = set of Char;
  52.  
  53. Function isKey : Boolean;
  54. Inline(
  55.  $B4/$B/   {mov ah,$B}
  56.  $CD/$21/  {int $21}
  57.  $24/$FE); {and al,$FE}
  58.  
  59. Function getKey : Char;
  60. Inline(
  61.  $B4/7/    {mov ah,7}
  62.  $CD/$21); {int $21}
  63.  
  64. Function input(default : String; maxCh : Byte; cs : tCharSet) : String;
  65.  
  66. Implementation
  67.  
  68. Function input(default : String; maxCh : Byte; cs : tCharSet) : String;
  69. Var
  70.   p : Byte;
  71.   c : Char;
  72.   s : String[255];
  73. begin
  74.   s := default;
  75.   Repeat
  76.     c := getKey;
  77.     if c = #0 then
  78.       c := Char(Byte(getKey) or $80);
  79.     Case c of
  80.       ^H :
  81.         if s[0] <> #0 then
  82.         begin
  83.           Write(^H, ' ', ^H);
  84.           dec(s[0]);
  85.         end;
  86.       #127 :
  87.         begin
  88.           For p := length(s) downto 1 do
  89.             Write(^H, ' ', ^H);
  90.             s[0] := #0;
  91.           end;
  92.       ^M : ; {don't beep}
  93.       ' '..'~' :
  94.         if length(s) < maxCh then
  95.         begin
  96.           Write(c);
  97.           inc(s[0]);
  98.           s[Byte(s[0])] := c;
  99.         end
  100.         else
  101.           Write(^G);
  102.  
  103.       else
  104.         if c in cs then
  105.         begin
  106.           s[1] := c;
  107.           s[0] := #1;
  108.           c    := ^M;
  109.         end
  110.         else
  111.           Write(^G);
  112.     end;
  113.   Until (c = ^M) or (c = ^[);
  114.  
  115.   if c = ^[ then
  116.     input := default
  117.   else
  118.     input := s;
  119.  
  120. end;
  121.  
  122. end.
  123.  
  124.